package com.example.boosttestandroid;

import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;

import com.example.boosttestandroid.adapter.MainFragmentAdapter;
import com.example.boosttestandroid.fragment.HomeFragment;
import com.example.boosttestandroid.fragment.UserFragment;
import com.example.boosttestandroid.interfac.OnClickTabListener;
import com.example.boosttestandroid.widget.CommonBottomBar;
import com.githang.statusbar.StatusBarCompat;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    private CommonBottomBar bottomBar;
    private List<Fragment> fragments = new ArrayList<>();
    private HomeFragment homeFragment;
    private UserFragment userFragment;
    private MainFragmentAdapter mainFragmentAdapter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initFragment();
        initView(savedInstanceState);
    }

    private void initFragment() {
        homeFragment = new HomeFragment();
        fragments.add(homeFragment);

        userFragment = new UserFragment();
        fragments.add(userFragment);

        mainFragmentAdapter = new MainFragmentAdapter(fragments, MainActivity.this, R.id.frame_centent, CommonBottomBar.HOME);
    }

    private void initView(@Nullable Bundle savedInstanceState) {
        setContentView(R.layout.activity_main);
        setStatusBar();

        bottomBar = findViewById(R.id.bar_bottom);
        bottomBar.setHome();
        bottomBar.setOnClickTabListener(new OnClickTabListener() {
            @Override
            public void onclick(int position) {
                switch (position) {
                    case CommonBottomBar.HOME:
                        mainFragmentAdapter.seletFragmentIndex(CommonBottomBar.HOME);
                        break;
                    case CommonBottomBar.ME:
                        mainFragmentAdapter.seletFragmentIndex(CommonBottomBar.ME);
                        break;
                    default:
                        break;
                }
            }
        });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    @Override
    protected void onPause() {
        super.onPause();
    }

    /**
     * 状态栏 需要重定义 重写此方法
     */
    protected void setStatusBar() {
        StatusBarCompat.setStatusBarColor(this, ContextCompat.getColor(this, R.color.colorTitleBar));
    }
}
